package com.duan.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ClassName DateUtil
 * @Description 日期函数信息
 * @Author duanlsh
 * @Date 2018/11/29 15:22
 * @Version 1.0
 */
public class DateUtil {



    public static List<String> getBetweenDate(Date beginDate, Date endDate){
        List<String> betweenDateList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(beginDate);

        for (long d = cal.getTimeInMillis(); d <= endDate.getTime(); d = getDayAddOne(cal)) {
            betweenDateList.add(sdf.format(d));
        }
        return betweenDateList;
    }

    public static long getDayAddOne(Calendar c) {
        c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + 1);
        return c.getTimeInMillis();
    }

    public static void main(String[] args) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date beginDate = sdf.parse("2018-11-19");
        Date endDate = sdf.parse("2018-11-29");
        List<String> resultList = getBetweenDate(beginDate,endDate);
        resultList.forEach(e -> {
            System.out.println(e);
        });
    }


}
